<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ItemOrder extends Model
{
    //订单状态: 1待支付,2支付成功,3支付失败
    const PAY_PENDING = 1;
    const PAID_SUCCESS = 2;
    const PAID_FAILURE = 3;

    /**
     * 是否待支付
     *
     * @return bool
     */
    public function isPending()
    {
        return $this->status == self::PAY_PENDING;
    }

    /**
     * 是否支付成功
     *
     * @return bool
     */
    public function isPaidSuccess()
    {
        return $this->status == self::PAID_SUCCESS;
    }

    /**
     * 信息
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function item()
    {
        return $this->belongsTo(Item::class);
    }

    /**
     * 用户信息
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function user()
    {
        return $this->belongsTo(User::class);
    }

    /**
     * 发布者信息
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function publisher()
    {
        return $this->belongsTo(User::class, 'publisher_uid');
    }

    /**
     * 申诉记录
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function appeal()
    {
        return $this->hasOne(ItemOrderAppeal::class, 'order_id');
    }

    /**
     * 留言
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function message()
    {
        return $this->hasOne(ItemOrderMessage::class, 'order_id');
    }
}
